<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/11
 * Time: 9:30
 */

namespace app\common\library\tencent;

use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Trtc\V20190722\Models\DissolveRoomRequest;
use TencentCloud\Trtc\V20190722\TrtcClient;

/*****  音视频房间管理  *****/
class Room
{
    protected $client;
    protected $req;
    public function __construct()
    {
        $cred = new Credential(config('SecretId'), config('SecretKey'));
        $httpProfile = new HttpProfile();
        $httpProfile->setEndpoint('trtc.tencentcloudapi.com');
        $clientProfile = new ClientProfile();
        $clientProfile->setHttpProfile($httpProfile);
        $this->client = new TrtcClient($cred, '', $clientProfile);
        $this->req = new DissolveRoomRequest();
    }
    /**
     * 销毁房间
     * @param $room_id 房间id
     * @return array
     * */
    public function destroyRoom($room_id){
        $params = json_encode([
            'SdkAppId'=>config('sdkAppID'),
            'RoomId'=>$room_id
        ]);
        $this->req->fromJsonString($params);
        $resp = $this->client->DissolveRoom($this->req);
        return json_decode($resp->toJsonString(),true);
    }

    public function __destruct()
    {
        unset($this->req);
        unset($this->client);
        // TODO: Implement __destruct() method.
    }


}